package com.theme.passport.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.utils.Query;
import com.theme.passport.dao.ThirdUserDao;
import com.theme.passport.entity.ThirdUserEntity;
import com.theme.passport.service.SysUserService;
import com.theme.passport.service.ThirdUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("thirdUserService")
public class ThirdUserServiceImpl extends ServiceImpl<ThirdUserDao, ThirdUserEntity> implements ThirdUserService {

    @Autowired
    private SysUserService sysUserService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ThirdUserEntity> page = this.page(
                new Query<ThirdUserEntity>().getPage(params),
                new QueryWrapper<ThirdUserEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public ThirdUserEntity queryByOpenid(int origin, String openid) {
        ThirdUserEntity thirdUser = baseMapper.queryByOpenid(origin, openid);
        return thirdUser;
    }

    @Override
    public Long insert(ThirdUserEntity thirdUserEntity) {
        int insert = baseMapper.insert(thirdUserEntity);
        return Long.valueOf(insert);
    }

    @Override
    public ThirdUserEntity queryByUserId(Long userId) {
        ThirdUserEntity thirdUser = baseMapper.queryByUserId(userId);
        return thirdUser;
    }

    @Override
    public void deleteById(Long id) {
        baseMapper.deleteById(id);
    }
}